package com.example.springbootstartermqttprovider.baidu;

import com.baidubce.auth.DefaultBceCredentials;
import com.baidubce.services.sms.SmsClient;
import com.baidubce.services.sms.SmsClientConfiguration;
import com.baidubce.services.sms.model.SendMessageV3Request;
import com.baidubce.services.sms.model.SendMessageV3Response;

import java.util.HashMap;
import java.util.Map;

public class TestSmsv3 {
    public static void main(String... args) {
        String ACCESS_KEY_ID = "ALTAKDofImhLFsACoDPhBGuztt";
        String SECRET_ACCESS_KEY = "72b7f59c9579410cb7bbe98f544ad6b6";
        String ENDPOINT = "https://sms.bj.baidubce.com";

        SmsClientConfiguration config = new SmsClientConfiguration();
        config.setCredentials(new DefaultBceCredentials(ACCESS_KEY_ID, SECRET_ACCESS_KEY));
        config.setEndpoint(ENDPOINT);
        SmsClient client = new SmsClient(config);

        SendMessageV3Request request = new SendMessageV3Request();
        request.setMobile("13723077835");
        request.setSignatureId("sms-sign-mZwozq14574");
        request.setTemplate("sms-tmpl-Rzhcik64637");
        Map<String, String> contentVar = new HashMap<>();
        contentVar.put("code", "23456");
        contentVar.put("minutes", "1");
        contentVar.put("appname", "金桥智运");
        request.setContentVar(contentVar);
        SendMessageV3Response response = client.sendMessage(request);
        // 解析请求响应 response.isSuccess()为true 表示成功
        if (response != null && response.isSuccess()) {
            //  submit success
        } else {
            //  fail
        }
    }
}